package com.glory.brepda.activity.mfg;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.glory.brepda.R;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.entity.BomEntity;
import com.glory.brepda.entity.LotInfoEntity;
import com.glory.brepda.entity.SuspendCodeBean;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.LotUtils;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralPop;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_PopUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class LotStopActivity extends BaseActivity {

    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.tvSuspendCode)
    TextView tvSuspendCode;
    @BindView(R.id.ivSuspendCodeArrow)
    ImageView ivSuspendCodeArrow;
    @BindView(R.id.flSuspendCodeList)
    FrameLayout flSuspendCodeList;
    @BindView(R.id.etLotID)
    FreeUI_ClearEditText etLotID;
    @BindView(R.id.etReason)
    FreeUI_ClearEditText etReason;
    @BindView(R.id.etMcomment)
    FreeUI_ClearEditText etMcomment;
    @BindView(R.id.etComment)
    FreeUI_ClearEditText etComment;
    @BindView(R.id.tvQty)
    TextView tvQty;
    @BindView(R.id.tvPackageType)
    TextView tvPackageType;
    @BindView(R.id.tvType)
    TextView tvType;
    @BindView(R.id.tvStepDesc)
    TextView tvStepDesc;

    private FreeUI_GeneralPop codePop;
    private ArrayList<String> suspendCodeList = new ArrayList<>();
    private ArrayList<SuspendCodeBean> suspendCodeBeanList = new ArrayList<>();
    @Override
    protected int getLayoutResId() {
        return R.layout.activity_lotsuspend;
    }

    @Override
    protected void initView() {

        String title = getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY);
        tvBaseSubmit.setText("提交");
        tvTitle.setText(title);
        setMainLayout(llMain);

    }

    @Override
    protected void initData() {

//        getSuspendCodeData();
//        for (SuspendCodeBean s: suspendCodeBeanList){
//            suspendCodeList.add(s.getValue());
//        }
        suspendCodeList.add("reserved_wafer");

        initEdit(etLotID,s ->{
            LotUtils.searchLotInfo(LotStopActivity.this, s, getSupportFragmentManager(), new LotUtils.netCallback<LotInfoEntity>() {
                @Override
                public void onSuccess(LotInfoEntity response) {
                    tvQty.setText(response.getLOT().getMAINQTY());
                    tvPackageType.setText(response.getPACKAGETYPE());
                    tvType.setText(response.getPART().getSPEC2());
                    tvStepDesc.setText(response.getLOT().getSTEPDESC());
                }

                @Override
                public void onFail(Throwable t) {
                    loadError(t, "LOTQUERY");
                }

            });
        });

    }

    @OnClick({R.id.tvBaseSubmit,R.id.flSuspendCodeList})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvBaseSubmit:
//                FreeUI_EntityCallBack<BaseResponseBean<BomEntity>> callBack = new FreeUI_DialogEntityCallBack<BaseResponseBean<BomEntity>>
//                        (new TypeToken<BaseResponseBean<BomEntity>>() {
//                        }.getType(), getSupportFragmentManager(), this) {
//
//                    @Override
//                    public void onSuccess(Response<BaseResponseBean<BomEntity>> response) {
//                        super.onSuccess(response);
//                        if (response.body().isSuccess(getApplicationContext(),true,getSupportFragmentManager())){
//                            showToast("放行成功",true);
//                        }
//                    }
//
//                    @Override
//                    public void onError(Response<BaseResponseBean<BomEntity>> response) {
//                        super.onError(response);
//                        loadError(response.getException(),"TOOLBOMBASIC");
//                    }
//                };
//
//                JsonObject map = new JsonObject();
//                map.addProperty("ACTIONTYPE","RESERVEDRELEASE");
//                map.addProperty("MLOTID",getText(etLotID));
//                map.addProperty("ACTIONCODE",tvSuspendCode.getText().toString());
//                map.addProperty("ACTIONREASON","线长放行预留片");
//                map.addProperty("ACTIONCOMMENT","线长放行预留片");
//                map.addProperty("COMMENT",getText(etComment));
//                NetUtils.requestPostNet("IF.MLOTHOLD","Common", LotStopActivity.this,map,callBack);

                break;
            case R.id.flSuspendCodeList:
                if (codePop != null) {
                    if (codePop.isShowing()) {
                        codePop.dismiss();
                    }
                } else {
                    codePop = FreeApi_PopUtils.getNormalPop(getApplicationContext(), flSuspendCodeList.getWidth(), suspendCodeList, ivSuspendCodeArrow, (codeS, i) -> {

                    });
                }
                FreeApi_PopUtils.setArrowShow(ivSuspendCodeArrow);
                codePop.showAsDropDown(flSuspendCodeList, 0, 0);
                break;
        }
    }

    private void getSuspendCodeData() {
        SuspendCodeBean s1 = new SuspendCodeBean();
        s1.setKey("H001");
        s1.setValue("数量异常");
        suspendCodeBeanList.add(s1);
        SuspendCodeBean s2 = new SuspendCodeBean();
        s2.setKey("H002");
        s2.setValue("工序不良率超标");
        suspendCodeBeanList.add(s2);
        SuspendCodeBean s3 = new SuspendCodeBean();
        s3.setKey("H003");
        s3.setValue("封装低良率");
        suspendCodeBeanList.add(s3);
        SuspendCodeBean s4 = new SuspendCodeBean();
        s4.setKey("H004");
        s4.setValue("测试后低良率");
        suspendCodeBeanList.add(s4);
        SuspendCodeBean s5 = new SuspendCodeBean();
        s5.setKey("H005");
        s5.setValue("品质异常");
        suspendCodeBeanList.add(s5);
        SuspendCodeBean s6 = new SuspendCodeBean();
        s6.setKey("H006");
        s6.setValue("OS超标");
        suspendCodeBeanList.add(s6);
        SuspendCodeBean s7 = new SuspendCodeBean();
        s7.setKey("H007");
        s7.setValue("客户要求暂扣");
        suspendCodeBeanList.add(s7);
        SuspendCodeBean s8 = new SuspendCodeBean();
        s8.setKey("H008");
        s8.setValue("新产品&新工艺，需验证");
        suspendCodeBeanList.add(s8);
        SuspendCodeBean s9 = new SuspendCodeBean();
        s9.setKey("H009");
        s9.setValue("产品存在风险，待工程验证");
        suspendCodeBeanList.add(s9);
        SuspendCodeBean s10 = new SuspendCodeBean();
        s10.setKey("H010");
        s10.setValue("其他，请注明");
        suspendCodeBeanList.add(s10);
        SuspendCodeBean s11 = new SuspendCodeBean();
        s11.setKey("VFCB");
        s11.setValue("VF超标");
        suspendCodeBeanList.add(s11);
        SuspendCodeBean s12 = new SuspendCodeBean();
        s12.setKey("低良停测");
        s12.setValue("低良停测");
        suspendCodeBeanList.add(s12);
        SuspendCodeBean s13 = new SuspendCodeBean();
        s13.setKey("WGCPCB");
        s13.setValue("外观次品超标");
        suspendCodeBeanList.add(s13);

    }

}
